<blockquote class="layui-elem-quote">
    <div class="layui-inline">
        <i class="layui-icon layui-icon-list layui-head-icon"></i>
        <span class="layui-font-16 layui-font-green">添加积分商品</span>
    </div>
</blockquote>
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form">
            <input type="hidden" name="goods_id" value="{$row.id}">
            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-block">
                    <input type="number" name="sort" value="{$row.sort|default=0}" lay-verify="required" placeholder=""
                           autoComplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">商品名称</label>
                <div class="layui-input-block">
                    <input type="text" name="goods_name" value="{$row.goods_name|default=''}" required
                           lay-verify="required"
                           placeholder="请输入商品名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">商品图片</label>
                <div class="layui-input-block">
                    <table class="layui-table" id="images">
                        <tr>
                            <th width="90px">商品主图</th>
                            <th>商品轮播图</th>
                        </tr>
                        <tr>
                            <td>
                                <img src="{$row.main_image|default='/static/admin/img/upimg.png'}" class="layui-upimg"
                                     id="main-image">
                            </td>
                            <td>
                                {notempty name='$row.goods_images'}
                                {foreach $row.goods_images as $img}
                                <div class="layui-inline">
                                    <img src="{$img}" class="layui-mul-upimg">
                                </div>
                                {/foreach}
                                {/notempty}
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <input type="hidden" name="spec_type" value="{$row.spec_type}">
            <div id="double" class="{if condition='!empty($row.spec_type) && $row.spec_type==1'} layui-hide {/if}">

                <div class="layui-form-item">
                    <label class="layui-form-label">商品规格</label>
                    <div class="layui-input-block">
                        <input type="hidden" name="goods_attr" id="attrs" value="{$row.goods_attr|default=''}">
                        <input type="hidden" name="skus" id="skus" value="{$row.items|default=''}">
                        <table class="layui-table" id="group-table">

                        </table>
                    </div>
                </div>
            </div>
            <div id="single"
                 class="{if condition='!empty($row.spec_type) && $row.spec_type==2'} layui-hide {/if} {empty name='row.spec_type'}layui-hide {/empty} ">
                <div class="layui-form-item">
                    <label class="layui-form-label">销售价</label>
                    <div class="layui-input-inline">
                        <input type="text" disabled value="{$row.sell_price}" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">总库存</label>
                    <div class="layui-input-inline">
                        <input type="text" disabled value="{$row.stock}" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">兑换积分</label>
                    <div class="layui-input-inline">
                        <input type="number" value="0" class="layui-input" name="redeem_integral">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">叠加价格</label>
                    <div class="layui-input-inline">
                        <input type="text" value="0" class="layui-input" name="redeem_price">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">库存</label>
                    <div class="layui-input-inline">
                        <input type="number" value="{$row.redeem_stock|default='0'}" class="layui-input"
                               name="redeem_stock">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">虚拟兑换数</label>
                <div class="layui-input-inline">
                    <input type="number" value="0" class="layui-input" name="redeem_num">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否上架</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" checked title="上架">
                    <input type="radio" name="status" value="0" title="下架">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formGoods">保存商品</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="/static/js/sku.js"></script>
<script src="/static/js/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        skuInit([
            {key: 'sell_price', val: '销售价', type: 'text'},
            {key: 'stock', val: '总库存', type: 'text'},
            {key: 'redeem_integral', val: '兑换积分', type: 'input'},
            {key: 'redeem_price', val: '兑换价格', type: 'input'},
            {key: 'redeem_stock', val: '兑换库存', type: 'input'},

        ])
    })

    layui.use('form', function () {
        var form = layui.form;

        form.on('submit(formGoods)', function (data) {
            $.post('/store/integral/goods/save', data.field, function (res) {
                if (res.code == 1) {
                    layer.msg(res.msg, {icon: 1});
                    location.href = '/store/integral/goods';
                    return false;
                }
                return layer.msg(res.msg, {icon: 2});
            });

            return false;
        });


    });
</script>